<%@ page import="com.beiyou.DbUtils" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ page import="com.beiyou.DbUtils" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="com.beiyou.DbUtils" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>上传文件</title>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
    <style>
        img {
            width: 50px;
            height: 50px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
<%--${pageContext.request.contextPath}/--%>
<div style="font-size: x-large"><a href="upfile.jsp">上传文件</a></div>

<hr>

<%
    DbUtils du = new DbUtils();
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        conn = du.getConn();
        String sql = "select id,name,ufile,utime,inet_ntoa(uip) ip from t_student order by id desc";
        ps = conn.prepareStatement(sql);
        rs = ps.executeQuery();
        while (rs.next()) {
            String n = rs.getString("name");
            String t = rs.getTimestamp("utime").toLocalDateTime().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss"));
            String ip = rs.getString("ip");
            out.print(String.format("<h3>上传人：%s，时间：%s，IP: %s</h3>", n, t, ip));
            out.print(String.format("<img src=\"upload/%s.jpg\"><hr>", rs.getString("ufile")));
        }
        du.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
%>

</body>
</html>
